//
//  FeedCell.m
//  xxShare
//
//  Created by 柳麟喆 on 2018/3/28.
//  Copyright © 2018年 lzLiu. All rights reserved.
//

#import "FeedCell.h"

@implementation FeedCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

#pragma mark - *******feedCellDelegate*******

- (IBAction)follow:(UIButton *)sender {
    if ([_delegate respondsToSelector:@selector(followBtnClicked:button:)]) {
        [_delegate followBtnClicked:self button:sender];
    }
}

- (IBAction)collection:(UIButton *)sender {
    if ([_delegate respondsToSelector:@selector(collectionBtnClicked:button:)]) {
        [_delegate collectionBtnClicked:self button:sender];
    }
}

- (IBAction)comment:(UITapGestureRecognizer *)sender {
    if ([_delegate respondsToSelector:@selector(commentBtnClicked:view:)]) {
        [_delegate commentBtnClicked:self view:_commentView];
    }
}

- (IBAction)thumb:(UITapGestureRecognizer *)sender {
    if ([_delegate respondsToSelector:@selector(thumbBtnClicked:view:)]) {
        [_delegate thumbBtnClicked:self view:_thumbView];
    }
}

- (IBAction)money:(UITapGestureRecognizer *)sender {
    if ([_delegate respondsToSelector:@selector(moneyBtnClicked:view:)]) {
        [_delegate moneyBtnClicked:self view:_moneyView];
    }
}

- (IBAction)photos:(UITapGestureRecognizer *)sender {
    if ([_delegate respondsToSelector:@selector(photosClicked:)]) {
        [_delegate photosClicked:_model.photos.copy];
    }
}


- (void)avatorImageViewClicked:(NSString *)accountID{
    if ([_delegate respondsToSelector:@selector(avatorClicked:)]) {
        [_delegate avatorClicked:self.model.accountID];
    }
}

#pragma mark - *******私有方法*******

- (void)setModel:(FeedModel *)model{
    _model = model;
    _nameAndDevote.text = [NSString stringWithFormat:@"%@(%@)",model.name,model.devote];
    _location.text = model.location;
    _time.text = model.time;
    _introduce.text = model.postContent;
    _tags.text = model.tags;
    _avator.image = [UIImage imageNamed:model.imageName];
    _photos.image = [UIImage imageNamed:model.photos.firstObject];
    _PhotoCounts.text = [NSString stringWithFormat:@"%d张", (int)_model.photos.count];
    _thumbNum.text = model.thumbNum;
    _commentNum.text = model.commentNum;
    _money.text = model.moneyNum;
    
    //给头像添加点击事件
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(avatorImageViewClicked:)];
    [_avator setUserInteractionEnabled:YES];
    [_avator addGestureRecognizer:tap];
}

- (IBAction)report:(UILongPressGestureRecognizer *)sender {
    if ([_delegate respondsToSelector:@selector(report)]) {
        [_delegate report];
    }
}


//- (CGSize)sizeThatFits:(CGSize)size {
//    CGFloat totalHeight = 0;
//    totalHeight += [_titleView sizeThatFits:size].height;
//    totalHeight += [_postView sizeThatFits:size].height;
//    totalHeight += [_photos sizeThatFits:size].height;
//    totalHeight += [_toolView sizeThatFits:size].height;
//    totalHeight += [_lineView sizeThatFits:size].height;
//    return CGSizeMake(size.width, totalHeight);
//}
@end
